/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package converters;

import com.mycompany.psc.ejb.ReportableItemsManager;
import com.mycompany.psc.entities.AluminiumOffers;
import javax.ejb.EJB;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author A7med
 */
@FacesConverter(forClass = AluminiumOffers.class,value = "aluDataConverter")
public class AlluminuimOffersConverter implements Converter{
    @EJB
    ReportableItemsManager rm;

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
         return rm.getResourceById("AluminiumOffers.findById",value);
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
       if(value instanceof AluminiumOffers){
            AluminiumOffers u=(AluminiumOffers)value;
           System.out.println("u="+u.getCompany());
        return ""+u.getId();
        }else{
            return "no value";
        }
    
    }
}
